﻿Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

Public Class FormMain
    Dim objUser As New clsUser
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Dim objFlbMst As New clsFlbMst
    Dim objGjbMst As New clsGjbMst
    Dim objGt As New clsGt
    Dim objGtResultDetails As New clsGtResultDetails
    Dim objGtNgReasonDetails As New clsGtNgReasonDetails
    Dim objGtProcedure As New clsGtProcedure
    Dim objGtProcedureDetails As New clsGtProcedureDetails
    Dim objProdSpec As New clsProdSpec
    Dim objDlMst As New clsDLMst
    Dim objDlDetailsMst As New clsDlDetailsMst
    Dim GJBEntity As New entity_GJB_DL_INFO
    Dim objGJBinfo As New clsGJBinfo
    Dim objPgdMesGt As New clsPgdMesGt
    Dim objWorkshopCurrent As New clsWorkshopCurrent
    Dim httpHelper As New HttpHelper
    Dim dgvSelectedSysId As String = "-1"
    Dim dttemp As New DataTable
    Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        dttemp.Columns.Add("b_gt_sys_id", GetType(String))
        dttemp.Columns.Add("ok_num", GetType(String))
        dttemp.Columns.Add("into_box_num", GetType(String))
        'connectDB()
        getUserListByCJ()
        initForm()
        Dim dt_gjb As DataTable = objProdSpec.getGJBAllList()
        If dt_gjb.Rows.Count > 0 Then
            cmbGJBType.DisplayMember = "mst_value"
            cmbGJBType.ValueMember = "size"
            cmbGJBType.DataSource = dt_gjb
        End If

        'If dt.Rows.Count > 0 Then
        '    cmb_Type.DisplayMember = "mst_name"
        '    cmb_Type.ValueMember = "mst_id"
        '    cmb_Type.DataSource = dt
        'End If

        'AddHandler cmb_Type.SelectedIndexChanged, AddressOf cmb_Type_SelectedIndexChanged
        'cmb_Type.SelectedIndex = 0
        'cmb_Type_SelectedIndexChanged(sender, e)

        setData()

    End Sub

    Private Sub connectDB()
        g_szInitFileName = My.Application.Info.DirectoryPath & "\Client_Gt_Gjb.ini"

        g_Server.szDrive = GetIniFile("SERVER", "DRIVE", "PostgreSQL ANSI", g_szInitFileName)
        g_Server.szIPadr = GetIniFile("SERVER", "IP", "", g_szInitFileName)
        g_Server.szDbn = GetIniFile("SERVER", "DBN", "ZHENANSF", g_szInitFileName)
        g_Server.szUid = GetIniFile("SERVER", "UID", "sa", g_szInitFileName)
        g_Server.szPas = GetIniFile("SERVER", "PAS", "sa", g_szInitFileName)
        g_Server.iOver = CInt(GetIniFile("SERVER", "OVER", "-1", g_szInitFileName))

        If False = g_fDBconnect And 0 = g_iDBconnResult Then
            If "" = g_Server.szIPadr Or "0.0.0.0" = g_Server.szIPadr Then
            Else
                g_fDBconnect = True

                'データベース接続
                With g_Server
                    g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    If 1 <> g_iDBconnResult Then
                        .szDrive = CStr(IIf("PostgreSQL" = .szDrive, "PostgreSQL ANSI", "PostgreSQL"))
                        g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    End If
                End With
            End If
        End If
    End Sub

    Private Sub getUserListByCJ()
        Dim dtUser As DataTable = objUser.getUserListByCJ(1)
        cmbOper.DisplayMember = "user_name"
        cmbOper.ValueMember = "user_id"
        cmbOper.DataSource = dtUser
        If String.IsNullOrEmpty(g_Current_UserID) = False Then
            cmbOper.SelectedValue = g_Current_UserID
        End If
        cmbOper.Enabled = False
    End Sub
    Public Sub initForm()
        Dim dttxx As DataTable = objWorkshopCurrent.GetListByWorkShopIdAndCurrentSection("1", "GJB")
        Dim dtProdS As DataTable = objProdSpec.selectAllbySpecId(dttxx.Rows(0)("support_model"))
        If dtProdS.Rows.Count > 0 Then
            cmb_MesPlan.Items.Clear()
            cmb_MesPlan.Items.Add(dtProdS.Rows(0)("mst_name"))
            cmb_MesPlan.Tag = dttxx.Rows(0)("b_pgd_sys_id").ToString()
            cmb_MesPlan.SelectedIndex = 0
            Dim dttPgdGtMes As DataTable = objPgdMesGt.getListById(dttxx.Rows(0)("b_pgd_sys_id"))
            'If dttPgdGtMes.Rows.Count > 0 Then
            '    cmb_MesPlan.Tag = dttPgdGtMes.Rows(0)("note")
            'Else
            '    cmb_MesPlan.Tag = String.Empty
            'End If
            lblPieceNum1.Text = dtProdS.Rows(0)("gjb_layer_num")
            If dttPgdGtMes.Rows.Count > 0 Then
                lblPlanCount.Text = dttPgdGtMes.Rows(0)("oper_count")
            Else
                lblPlanCount.Text = "0"
            End If
        Else
            cmb_MesPlan.Items.Clear()
            cmb_MesPlan.Text = String.Empty
            cmb_MesPlan.Tag = String.Empty
            lblPieceNum1.Text = "0"
            lblPlanCount.Text = "0"
        End If
    End Sub

    Private Sub btnMesWorkReport_Click(sender As Object, e As EventArgs) Handles btnMesWorkReport.Click
        Dim formMesWorkReport As New FormMesWorkReport()
        formMesWorkReport.usr = cmbOper.Text.Trim()
        formMesWorkReport.ShowDialog(Me)
    End Sub

    Private Sub btnMesWorkReportList_Click(sender As Object, e As EventArgs) Handles btnMesWorkReportList.Click
        Dim formMesWorkReportList As New FormMesWorkReportList()
        formMesWorkReportList.ShowDialog(Me)
    End Sub

    Private Sub btnAssemblingRecord_Click(sender As Object, e As EventArgs) Handles btnAssemblingRecord.Click
        Dim formAssemblingRecord As New FormAssemblingRecord()
        formAssemblingRecord.ShowDialog(Me)
    End Sub

    Private Sub btnDlHistoryRecord_Click(sender As Object, e As EventArgs) Handles btnDlHistoryRecord.Click
        Dim formGjbInfoList As New FormGjbInfoList()
        formGjbInfoList.ShowDialog(Me)
    End Sub

    Private Sub btnDlSearch_Click(sender As Object, e As EventArgs) Handles btnDlSearch.Click
        Dim formDlnfo As New FormDlnfo()
        formDlnfo.ShowDialog(Me)
    End Sub

    Private Sub btnFresh_Click(sender As Object, e As EventArgs) Handles btnFresh.Click
        setData()
    End Sub

    Public Sub setData()
        Dim dt As DataTable = objGt.getCurrentGt("0", "1", "2", "2")
        dt.Columns.Add("oper_type_name")
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If row("oper_type") = "0" Then
                    row("oper_type_name") = "骨架板"
                Else
                    row("oper_type_name") = "法兰板"
                End If
            Next
        End If
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dt
    End Sub

    Public Sub setDgvOperData()
        If dgv.SelectedRows.Count > 0 Then
            Dim dtProcedure As DataTable = objGtProcedure.selectGtProcedure(dgv.SelectedRows(0).Cells("sys_id").Value.ToString(), "2")
            DataGridView3.AutoGenerateColumns = False
            DataGridView3.DataSource = dtProcedure
            Dim dtOper As DataTable = objGtProcedureDetails.getGtProcedureDetailsList(dgv.SelectedRows(0).Cells("sys_id").Value.ToString(), "2")
            dgvOper.AutoGenerateColumns = False
            dgvOper.DataSource = dtOper
        Else
            DataGridView3.AutoGenerateColumns = False
            DataGridView3.DataSource = New DataTable()
            dgvOper.AutoGenerateColumns = False
            dgvOper.DataSource = New DataTable()
        End If
    End Sub

    Public Sub SetDgvResultData()
        If dgv.SelectedRows.Count > 0 Then
            Dim dtResult As DataTable = objGtResultDetails.getGtResultDetailsList(dgv.SelectedRows(0).Cells("sys_id").Value.ToString(), "2")
            DataGridView2.AutoGenerateColumns = False
            DataGridView2.DataSource = dtResult
        Else
            DataGridView2.AutoGenerateColumns = False
            DataGridView2.DataSource = New DataTable()
        End If
    End Sub

    Public Sub setDgvNgOperData()
        If dgv.SelectedRows.Count > 0 Then
            Dim dtNgOper As DataTable = objGtNgReasonDetails.getGtNgDetailsList(dgv.SelectedRows(0).Cells("sys_id").Value.ToString(), "2")
            dgvNgOper.AutoGenerateColumns = False
            dgvNgOper.DataSource = dtNgOper
            Dim dtt As DataTable = objGJBinfo.getGjbInfoListByGtSysId(dgvSelectedSysId)
            Dim dttetails As DataTable = objGJBinfo.getGjbInfoDetailsListByGtSysId(dgvSelectedSysId)
            SpinEdit3.Value = dtt.Rows(0)("layer_num_all")
            If DataGridView2.Rows.Count > 0 Then
                SpinEdit2.Value = Integer.Parse(DataGridView2.Rows(0).Cells("C_ok_num").Value.ToString()) - Integer.Parse(dtt.Rows(0)("layer_num_all").ToString()) - Integer.Parse(dttetails.Rows(0)("piece_num_all").ToString())
            End If
        Else
            dgvNgOper.AutoGenerateColumns = False
            dgvNgOper.DataSource = New DataTable()
            SpinEdit3.Value = 0
            SpinEdit2.Value = 0
        End If
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            dgvSelectedSysId = dgv.Rows(dgv.CurrentRow.Index).Cells("sys_id").Value.ToString()
            cmbGJBType.Text = dgv.SelectedRows(0).Cells("type_value").Value.ToString()
            setDgvOperData()
            SetDgvResultData()
            setDgvNgOperData()
        Else

        End If
    End Sub

    Private Sub btnNg_Click(sender As Object, e As EventArgs) Handles btnNg.Click
        If dgvOper.SelectedRows.Count > 0 Then
            Dim formNgOper As New FormNgOper()
            formNgOper.usr = cmbOper.Text.Trim()
            formNgOper.source = "6gw"
            formNgOper.ty = "0"
            formNgOper.b_gt_sys_id = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
            formNgOper.current_procedure_No = 2
            formNgOper.ng_num_all = DataGridView2.SelectedRows(0).Cells("Co_ng_num").Value.ToString()
            formNgOper.oper_num_all = DataGridView3.SelectedRows(0).Cells("Col_oper_num").Value.ToString()
            formNgOper.ShowDialog(Me)
        End If
    End Sub

    Private Sub btnValidity_Click(sender As Object, e As EventArgs) Handles btnValidity.Click
        If dgvNgOper.SelectedRows.Count > 0 Then
            If dgvNgOper.SelectedRows(0).Cells("Colu_validity").Value.ToString().Equals("1") Then
                If MsgBox("确认要进行作废吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgvNgOper.SelectedRows(0).Cells("Colu_sys_id").Value.ToString()
                    Dim procedure_no As String = dgvNgOper.SelectedRows(0).Cells("Colu_procedure_no").Value.ToString()
                    Dim b_gt_sys_id As String = dgvNgOper.SelectedRows(0).Cells("Colu_b_gt_sys_id").Value.ToString()
                    Dim ng_num As String = dgvNgOper.SelectedRows(0).Cells("Colu_ng_num").Value.ToString()
                    Dim rtn As Integer = objGtNgReasonDetails.updateValidity(sys_id, ng_num, b_gt_sys_id, procedure_no, cmbOper.Text.Trim())
                    If rtn <> -2 Then
                        MsgBox("作废成功", vbYes, "提示")
                        SetDgvResultData()
                        setDgvNgOperData()
                    Else
                        MsgBox("作废失败", vbYes, "提示")
                    End If
                End If
            Else
                MsgBox("该记录已作废", vbYes, "提示")
            End If
        End If
    End Sub

    Private Sub btnFinish_Click(sender As Object, e As EventArgs) Handles btnFinish.Click
        If dgv.SelectedRows.Count > 0 Then
            If MsgBox("确认完工吗？", vbYesNo, "提示") = vbYes Then
                If String.IsNullOrEmpty(cmb_MesPlan.Tag.ToString()) = False Then
                    Dim sys_id As String = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
                    Dim rtn As Integer = objGt.save("3", cmb_MesPlan.Tag.ToString(), sys_id)
                    If rtn <> -2 Then
                        objGt.saveOkNg(sys_id)
                        MsgBox("完工成功", vbYes, "提示")
                        setData()
                        setDgvOperData()
                        SetDgvResultData()
                        setDgvNgOperData()
                    Else
                        MsgBox("完工失败", vbYes, "提示")
                    End If
                Else
                    MsgBox("未获取到生产计划信息，请进行生产设定", vbYes, "提示")
                End If
            End If
        End If
    End Sub

    Private Sub ComboBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles cmb_Type.DrawItem
        'If e.Index < 0 Then
        '    Exit Sub
        'End If
        'e.DrawBackground()
        'e.DrawFocusRectangle()
        'e.Graphics.DrawString(cmb_Type.Items(e.Index)(0).ToString(), e.Font, New SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 10)
    End Sub
    Private Sub cmb_Type_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb_Type.SelectedIndexChanged
        If cmb_Type.SelectedIndex > -1 Then
            Dim _dt0 As DataTable = objProdSpec.selectAllbySpecId(cmb_Type.SelectedValue.ToString)
            If _dt0.Rows.Count > 0 Then
                lblPieceNum.Text = _dt0.Rows(0)("gjb_layer_num")
            Else
                lblPieceNum.Text = "0"
            End If
        End If
    End Sub

    Private Sub cmbGJBType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbGJBType.SelectedIndexChanged
        If cmbGJBType.SelectedIndex > -1 Then
            lblSize.Text = cmbGJBType.SelectedValue.ToString
            Dim dt As DataTable = objProdSpec.getSpecANDName(cmbGJBType.Text)
            cmb_Type.DisplayMember = "mst_name"
            cmb_Type.ValueMember = "prod_spec_id"
            cmb_Type.DataSource = dt
            If dt.Rows.Count > 0 Then
                cmb_Type.SelectedIndex = 0
            End If
        End If
    End Sub

    Private Sub txtNum_MouseDown(sender As Object, e As MouseEventArgs) Handles txtNum.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = False
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub
    Private Sub txtWeight_MouseDown(sender As Object, e As MouseEventArgs) Handles txtWeight.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        UcDigitalKeyboard1.B_01 = True
        UcDigitalKeyboard1.B_02 = False

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub
    Private Sub ucdigitalkeyboard1_leave(sender As Object, e As EventArgs) Handles UcDigitalKeyboard1.Leave
        UcDigitalKeyboard1.Dispose()
    End Sub

    Private Sub setGJBEntity()
        With GJBEntity
            .dl_no_lr = txtDLNo.Text
            .dl_no = txtDLNo.Text.Remove(txtDLNo.Text.Length - 1)
            .pgd_id = cmb_MesPlan.Tag.ToString()
            If rbMesPlan.Checked Then
                Dim dttzs As DataTable = objPgdMesGt.getListById(cmb_MesPlan.Tag.ToString())
                .support_model = dttzs.Rows(0)("support_model")
            End If
            If rbProdSpec.Checked Then
                .support_model = cmb_Type.SelectedValue.ToString
            End If
            .material_code = dgv.SelectedRows(0).Cells("material_code").Value.ToString()
            .gjb_type = cmbGJBType.Text
            .layer_num = txt_current_all_num.Text
            .wt = CDbl(txtWeight.Text)
            .status = 0
            .b_gt_sys_id = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
            .Ope = cmbOper.Text
            .label_No = txtLabelNo.Text
        End With

    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If dgv.SelectedRows.Count <= 0 Then
            MsgBox("请选择当前生产骨架板信息", vbYes, "提示")
            Exit Sub
        End If
        If rbMesPlan.Checked Then
            Dim dttxx1 As DataTable = objWorkshopCurrent.GetListByWorkShopIdAndCurrentSection("1", "GJB")
            Dim dtProdS1 As DataTable = objProdSpec.selectAllbySpecId(dttxx1.Rows(0)("support_model"))
            If dgv.SelectedRows(0).Cells("material_code").Value.ToString().Equals(dtProdS1.Rows(0)("gjb_material_code").ToString()) = False Then
                MsgBox("当前生产骨架板与生产设定不一致！", vbYes, "提示")
                Exit Sub
            End If
        End If
        If txtDLNo.Text = "" Then
            MsgBox("请输入吊篮号！", vbYes, "提示")
            txtDLNo.Focus()
            Exit Sub
        End If
        If txtNum.Text = "" OrElse CInt(txtNum.Text) <= 0 Then
            MsgBox("请输入片数！", vbYes, "提示")
            txtNum.Focus()
            Exit Sub
        End If

        If txtWeight.Text = "" OrElse CDbl(txtWeight.Text) <= 0 Then
            MsgBox("请输入重量！", vbYes, "提示")
            txtWeight.Focus()
            Exit Sub
        End If
        If txtLabelNo.Text = "" Then
            MsgBox("请输入标签号！", vbYes, "提示")
            txtLabelNo.Focus()
            Exit Sub
        End If

        If rbMesPlan.Checked Then
            If CInt(txtNum.Text) > CInt(lblPieceNum1.Text) Then
                MsgBox("输入片数 > 生产计划支座设计片数", vbYes, "提示")
                txtNum.Focus()
                Exit Sub
            End If
        End If
        If rbProdSpec.Checked Then
            If CInt(txtNum.Text) > CInt(lblPieceNum.Text) Then
                MsgBox("输入片数 > 成品支座设计片数", vbYes, "提示")
                txtNum.Focus()
                Exit Sub
            End If
        End If
        If txtNum.Value > (SpinEdit2.Value) Then
            MsgBox("输入片数 > 可装配数量，请核查！", vbYes, "提示")
            txtNum.Focus()
            Exit Sub
        End If
        'Dim dtDlDetails As DataTable = objDlDetailsMst.selectAll(txtDLNo.Text.Remove(txtDLNo.Text.Length - 1), g_gjb_type_0.ToString(), cmbGJBType.Text, g_validity_1)
        'If dtDlDetails.Rows.Count = 0 Then
        '    MsgBox("当前骨架板料框不支持骨架板规格型号，" & lblDLCaption.Text)
        '    txtDLNo.Focus()
        '    Exit Sub
        'End If
        If dgvAssembling.Rows.Count < 1 Then
            MsgBox("请添加料框数量！", vbYes, "提示")
            Exit Sub
        End If
        Dim dtGjbInfo As DataTable = objGJBinfo.getGjbInfoByBarCode(txtLabelNo.Text.Trim())
        If dtGjbInfo.Rows.Count = 0 Then
            setGJBEntity()
            Dim rtn As Integer
            If dgvAssembling.Rows.Count = 1 Then
                rtn = objGJBinfo.save(GJBEntity) <> -2
            ElseIf dgvAssembling.Rows.Count > 1 Then
                GJBEntity.b_gt_sys_id = "0"
                rtn = objGJBinfo.save(GJBEntity, dttemp)
            End If
            If rtn <> -2 Then
                MsgBox("保存成功", vbYes, "提示")
                setDgvNgOperData()
                dttemp.Rows.Clear()
                dgvAssembling.Refresh()
                txtNum.Value = 0
                txt_current_all_num.Value = 0
                txtDLNo.Text = ""
                txtNum.Text = 0
                txtWeight.Text = 0
                txtLabelNo.Text = ""
                txtDLNo.Focus()
            Else
                MsgBox("保存失败", vbYes, "提示")
            End If
        Else
            MsgBox("此料框有未使用记录，无法装框，请核查！", vbYes, "提示")
        End If
    End Sub

    Private Sub txtDLNo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtDLNo.KeyDown
        If e.KeyCode = Keys.Enter Then
            If String.IsNullOrEmpty(txtDLNo.Text.Trim()) = False Then
                txtDLNo.Text = txtDLNo.Text.Trim().ToUpper()
                Dim dtDlMst As DataTable = objDlMst.selectGjbDLByBarCode(txtDLNo.Text.Trim())
                If dtDlMst.Rows.Count = 1 Then
                    If txtDLNo.Text.Trim().ToUpper().EndsWith("L") Or txtDLNo.Text.Trim().ToUpper().EndsWith("R") Then
                        txtLabelNo.Text = txtDLNo.Text.Trim().Substring(0, txtDLNo.Text.Trim().Length - 1)
                    Else
                        txtLabelNo.Text = String.Empty
                    End If
                Else
                    If dtDlMst.Rows.Count <= 0 Then
                        MsgBox("此条码号，不存在，请核查")
                    Else
                        MsgBox("此条码号，存在多条记录，请核查")
                    End If
                End If
            End If
            'objGJBinfo.setdefaultValue(txtDLNo.Text, txtNum, txtWeight, Nothing, Nothing, txtLabelNo)
        End If
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If String.IsNullOrEmpty(txtDLNo.Text.Trim()) = False Then
            Dim dtDlMst As DataTable = objDlMst.selectGjbDLByBarCode(txtDLNo.Text.Trim())
            If dtDlMst.Rows.Count = 1 Then
                If txtDLNo.Text.Trim().ToUpper().EndsWith("L") Or txtDLNo.Text.Trim().ToUpper().EndsWith("R") Then
                    txtLabelNo.Text = txtDLNo.Text.Trim().Substring(0, txtDLNo.Text.Trim().Length - 1)
                Else
                    txtLabelNo.Text = String.Empty
                End If
            Else
                If dtDlMst.Rows.Count <= 0 Then
                    MsgBox("此条码号，不存在，请核查")
                Else
                    MsgBox("此条码号，存在多条记录，请核查")
                End If
            End If
        End If
        'objGJBinfo.setdefaultValue(txtDLNo.Text, txtNum, txtWeight, Nothing, Nothing, txtLabelNo)
    End Sub

    Private Sub btnSet_Click(sender As Object, e As EventArgs) Handles btnSet.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim formPlanMes As New FormPlanMes()
            formPlanMes.usr = cmbOper.Text.ToString()
            formPlanMes.ok_num = dgv.SelectedRows(0).Cells("ok_num").Value.ToString()
            formPlanMes.b_gt_sys_id = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
            formPlanMes.material_code = dgv.SelectedRows(0).Cells("material_code").Value.ToString()
            formPlanMes.ShowDialog(Me)
        Else
            MsgBox("请选择当前生产的骨架板", vbYes, "提示")
        End If
    End Sub

    Private Sub btnGJBZLRecord_Click(sender As Object, e As EventArgs) Handles btnGJBZLRecord.Click
        Dim formGJBZLRecord As New FormGJBZLRecord()
        formGJBZLRecord.ShowDialog(Me)
    End Sub

    Private Sub txtDLNo_TextChanged(sender As Object, e As EventArgs) Handles txtDLNo.TextChanged
        If txtDLNo.Text.Length = 0 Then
            txtLabelNo.Text = String.Empty
        End If
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        Dim rtn As Integer = objWorkshopCurrent.updateDataClear("1", "GJB")
        If rtn = -2 Then
            MsgBox(btnClear.Text + "失败")
        Else
            MsgBox(btnClear.Text + "成功")
            initForm()
        End If
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        If dgv.SelectedRows.Count > 0 Then
            If txtNum.Value > 0 Then
                Dim b_success As Boolean = True
                If dttemp.Rows.Count > 0 Then
                    For index = 0 To dttemp.Rows.Count - 1
                        If dttemp.Rows(index)("b_gt_sys_id").Equals(dgv.SelectedRows(0).Cells("sys_id").Value.ToString()) Then
                            b_success = False
                            Exit For
                        End If
                    Next
                End If
                If b_success Then
                    dttemp.Rows.Add(dgv.SelectedRows(0).Cells("sys_id").Value.ToString(),
                                dgv.SelectedRows(0).Cells("ok_num").Value.ToString(),
                                txtNum.Value.ToString())
                    txt_current_all_num.Value = txt_current_all_num.Value + txtNum.Value
                    dgvAssembling.AutoGenerateColumns = False
                    dgvAssembling.DataSource = dttemp
                Else
                    MsgBox("该入料信息及装框数量已添加！", vbYes, "提示")
                End If
            Else
                MsgBox("装配数量需 > 0！", vbYes, "提示")
            End If
        Else
            MsgBox("请选择当前生产信息！", vbYes, "提示")
        End If
    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        If dgvAssembling.Rows.Count > 0 Then
            If MsgBox("您确定要进行删除吗？", MsgBoxStyle.OkCancel, "提示") = MsgBoxResult.Ok Then
                txt_current_all_num.Value = txt_current_all_num.Value - dttemp.Rows(dgvAssembling.SelectedRows(0).Index)("into_box_num")
                dttemp.Rows.RemoveAt(dgvAssembling.SelectedRows(0).Index)
            End If
        End If
    End Sub

    Private Sub FormMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        DBacs.Disconnect()
    End Sub

    Private Sub dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)

    End Sub
End Class

Public Class entity_GJB_DL_INFO
    Public sys_id As String
    Public factory_id As String
    Public dl_no_lr As String
    Public dl_no As String
    Public pgd_id As String
    Public support_model As String
    Public material_code As String
    Public gjb_type As String
    Public layer_num As String
    Public wt As Double
    Public status As String
    Public b_gt_sys_id As String
    Public Ope As String
    Public used_date As DateTime
    Public update_time As DateTime
    Public label_No As String
End Class
